
/**
 * Module dependencies.
 */

var express = require('express')
  , routes = require('./routes')
  , http = require('http')
  , path = require('path')
  , model = require('./models');

var app = express();
var server = http.createServer(app);
var hash = require('./hash.js').hash;

app.configure(function(){
  app.set('port', process.env.PORT || 8080);
  app.set('views', __dirname + '/views');
  app.set('view engine', 'ejs');
  app.use(express.favicon());
  app.use(express.logger('dev'));
  app.use(express.bodyParser({uploadDir:'./uploads'}));
  app.use(express.methodOverride());
  app.use(app.router);
  app.use(express.static(path.join(__dirname, 'public')));
});

app.configure('development', function(){
  app.use(express.errorHandler());
});

routes(app);
server.listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});
function getType(o) { 
  var _t; 
  return ((_t = typeof(o)) == "object" ? o==null && "null" || Object.prototype.toString.call(o).slice(8,-1):_t).toLowerCase(); 
}
function diffArray(a,b){
  //求a和b的差异集合,即a-b
  if((getType(a) != 'array')||(getType(b) != 'array')){return null;}
  var aNum = a.length;
  var bNum = b.length;
  if(aNum<bNum){return null;}
  var ret = [];
  var tmp = [];
  for(var i = 0; i < bNum; i++){
    tmp[b[i]] = true;
  }
  for(var i = 0; i < aNum; i++){
    if(!tmp[a[i]]){
      ret.push(a[i]);
    }
  }
  return ret;
}
Array.prototype.find = function(ele){
  var len = this.length;
  for(var i = len-1; i >= 0; i--){
    if(this[i] == ele){
      return i;
    }
  }
  return -1;
}
function output(data){
  for(var key in data){
    console.log(key+'='+data[key]);
  }
}